# 11. H 指数.py
from typing import List

class Common_Solution:
    def hIndex(self, citations: List[int]) -> int:
        n = len(citations)
        ans = 0
        for i in range(1, n+1):
            count = 0
            for citation in citations:
                if citation >= i:
                    count += 1
                if count > i:
                    break
            if count >= i:
                ans = i
        return ans

class Solution:
    def hIndex(self, citations: List[int]) -> int:
        n = len(citations)
        # citations = sorted(citations, reverse=True)  # 递减顺序，非原地排序
        citations.sort(reverse=True)
        hIndex = 0
        for citation in citations:
            if citation > hIndex:
                hIndex += 1
            # 剪枝增效
            elif citation <= hIndex:
                break
        return hIndex

# 本题的官方题解中有进行二分搜索和计数排序的思路，后续可以进一步学习。